package com.freesky.biz.rights.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.freesky.biz.citic.domain.TCiticLucky;
import com.freesky.biz.rights.domain.RightsMobileRechargeEntity;
import com.freesky.biz.rights.domain.RightsReceiveEntity;
import com.freesky.biz.rights.service.IRightsMobileRechargeService;
import com.freesky.biz.rights.service.IRightsReceiveService;
import com.freesky.common.annotation.Log;
import com.freesky.common.annotation.RepeatSubmit;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/rights/mobile/recharge")
public class RightsMobileRechargeController extends BaseController {

    @Autowired
    private IRightsMobileRechargeService mobileRechargeService;

    /**
     * 权益领取记录列表
     */
    @PreAuthorize("@ss.hasPermi('rights:mobilerecharge:list')")
    @GetMapping("/list")
    public TableDataInfo list(RightsMobileRechargeEntity entity) {
        IPage<RightsMobileRechargeEntity> pageList = mobileRechargeService.selectRightsMobileRechargePage(plusPage(),entity);
        return getDataTable(pageList);
    }

    @Log(title = "通用话费充值", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('rights:mobilerecharge:list')")
    @RepeatSubmit
    @PostMapping("/updateRechargeById")
    public AjaxResult updateRechargeById(@Validated @RequestBody RightsMobileRechargeEntity entity,
                                         HttpServletResponse response) {
        entity.setProcessed("4");
        mobileRechargeService.updateManualById(entity.getId(),entity.getProcessed());
        return AjaxResult.success();
    }

    @Log(title = "通用话费充值", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('rights:mobilerecharge:export')")
    @GetMapping("/export")
    public AjaxResult export(RightsMobileRechargeEntity entity,
                             HttpServletResponse response) {
        return mobileRechargeService.exportFile(entity);
    }

}
